package cn.hxzy.course.mapper;

import cn.hxzy.common.domain.FileInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface FileInfoMapper  extends BaseMapper<FileInfo> {
    @Insert("INSERT INTO file_info (section_id,info_name,info_path) VALUES (#{sectionId},#{infoName},#{infoPath})")
    int insert(FileInfo fileInfo);

    //资料名称模糊查询
    @Select("SELECT \n" +
            "    fi.info_name,\n" +
            "    fi.info_path\n" +
            "FROM \n" +
            "    sys_course AS sc\n" +
            "JOIN \n" +
            "    sys_chapter AS sch ON sc.course_id = sch.course_id\n" +
            "JOIN \n" +
            "    sys_section AS ss ON sch.chapter_id = ss.chapter_id\n" +
            "JOIN \n" +
            "    file_info AS fi ON ss.section_id = fi.section_id\n" +
            "WHERE \n" +
            "    sc.course_id = #{courseId}\n" +
            "    AND fi.info_name LIKE '%${infoName}%'\n" +
            "    AND sc.deleted = 0\n" +
            "    AND sch.deleted = 0;")
    List<FileInfo> selectFileInfo(String infoName,Integer courseId);

    //查此课程所有资料
    @Select("SELECT COUNT(0) FROM file_info WHERE section_id IN(\n" +
            "SELECT section_id FROM sys_section WHERE chapter_id IN(\n" +
            "SELECT chapter_id FROM sys_chapter WHERE course_id=#{courseId}))")
    double selectCount(Long courseId);

    @Select("select * from file_info where section_id=#{sectionId}")
    List<FileInfo> selectFileInfoNum(Integer sectionId);

    //删除资料
    @Delete("DELETE FROM file_info WHERE info_id=#{infoId}")
    int deleteFileInfo(Integer infoId);
}
